package com.cj.eduservice.controller.front;

import com.cj.commonutils.R;
import com.cj.eduservice.entity.EduCourse;
import com.cj.eduservice.entity.EduTeacher;
import com.cj.eduservice.service.EduCourseService;
import com.cj.eduservice.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author cj
 * @date 2023/4/10 14:50
 * @description
 */
@RestController
@RequestMapping("/eduservice/indexfront")
//@CrossOrigin
public class IndexFrontController {
    @Autowired
    private EduCourseService courseService;
    @Autowired
    private EduTeacherService teacherService;
    //查询前8条热门课程，查询前4条名师
    @GetMapping("index")
    public R index() {
        //查询前8条热门课程
        //QueryWrapper<EduCourse> wrapper = new QueryWrapper<>();
        //wrapper.orderByDesc("view_count");
        //wrapper.last("limit 8");
        //List<EduCourse> eduList = courseService.list(wrapper);

        List<EduCourse> eduCourseList = courseService.selectHotCourses();

        //查询前4条名师
        //QueryWrapper<EduTeacher> wrapperTeacher = new QueryWrapper<>();
        //wrapperTeacher.orderByDesc("id");
        //wrapperTeacher.last("limit 4");
        //List<EduTeacher> teacherList = teacherService.list(wrapperTeacher);

        List<EduTeacher> eduTeachersList = teacherService.selectHotTeacher();

        return R.ok().data("eduList",eduCourseList).data("teacherList",eduTeachersList);
    }

}
